package saucaca.fragment;

import java.util.ArrayList;

import lemon.kenhnhacvn.MainActivity;
import lemon.kenhnhacvn.R;
import saucaca.CustomView.PagerSlidingTabStrip;
import saucaca.Object.TelcoObject;
import saucaca.Slidingmenu.SlidingMenu;
import saucaca.Util.CMD;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


public class InforFragment extends Fragment {
	MainActivity mActivity;
	ViewPager viewPager;
	InforAdapter adapter;
	PagerSlidingTabStrip tabs;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@SuppressLint("NewApi")
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//		getActivity().getActionBar().hide();
		View view = inflater.inflate(R.layout.viewpager_tabstrip, container, false);
		findViewById(view);
		mActivity.myActionBar.setMenu(R.string.menu_thongtin, false, true);
		return view;
	}
	@Override
	public void onHiddenChanged(boolean hidden) {
		super.onHiddenChanged(hidden);
		mActivity.myActionBar.setMenu(R.string.menu_thongtin, false, true);
	}

	public void findViewById(View view) {
		viewPager = (ViewPager) view.findViewById(R.id.viewPager);
		tabs = (PagerSlidingTabStrip) view.findViewById(R.id.tabs);
		adapter = new InforAdapter(getChildFragmentManager());
		final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
		viewPager.setPageMargin(pageMargin);
		viewPager.setAdapter(adapter);
		viewPager.setCurrentItem(0);
		tabs.setViewPager(viewPager);
		tabs.setOnPageChangeListener(new OnPageChangeListener() {
			@Override
			public void onPageSelected(int arg0) {
				switch (arg0) {
				case 0:
					mActivity.getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
					break;
				default:
					mActivity.getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
					break;
				}
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
			}
		});
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		if (activity instanceof MainActivity) {
			mActivity = (MainActivity) activity;
		}
	}

	public class InforAdapter extends FragmentStatePagerAdapter {
		ArrayList<TelcoObject> listTelco;
		String[] infoTitle = { "Giới thiệu", "Hướng dẫn", "Điều khoản", };
		String[] infoVALUE = { CMD.GUIDE_ABOUT, CMD.GUIDE_GUIDE, CMD.GUIDE_RULE };

		public InforAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return infoTitle[position];
		}

		@Override
		public int getCount() {
			return infoTitle.length;
		}

		@Override
		public Parcelable saveState() {
			return null;
		}

		@Override
		public Fragment getItem(int i) {
			return new InfoDetailFragment(infoVALUE[i]);
		}
	}
}
